/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import com.toedter.calendar.IDateEvaluator;
import entity.HolidayDetail;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Kien Chinh
 */
public class DateEvaluator implements IDateEvaluator {

    ArrayList<HolidayDetail> list;
    Calendar calendar = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();

    public DateEvaluator(ArrayList<HolidayDetail> list) {
        this.list = list;
    }

    @Override
    public boolean isSpecial(Date date) {
        calendar2.setTime(date);
        if (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH) && calendar.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH)) {
            return true;
        }
        return false;
    }

    @Override
    public Color getSpecialForegroundColor() {
        return Color.BLACK;
    }

    @Override
    public Color getSpecialBackroundColor() {
        return Color.BLACK;
    }

    @Override
    public String getSpecialTooltip() {
        return "Holiday";
    }

    @Override
    public boolean isInvalid(Date date) {
        calendar2.setTime(date);
        for (int i = 0; i < list.size(); i++) {
            calendar.setTime(list.get(i).getStartday());
            if (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH) && calendar.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public Color getInvalidForegroundColor() {
        return Color.GREEN;
    }

    @Override
    public Color getInvalidBackroundColor() {
        return Color.GREEN;
    }

    @Override
    public String getInvalidTooltip() {
        return "Holiday";
    }
}
